package com.xingkeduo.business.transformation.json;

import com.fasterxml.jackson.databind.node.ArrayNode;
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.xingkeduo.pojo.table.ConsumerRelateTO;
import com.xingkeduo.util.pojo.base.BaseJson;
import com.xingkeduo.util.tool.CommonUtil;
import org.springframework.stereotype.Component;

import java.util.Iterator;
import java.util.List;

/**
 * @Description:
 * @Author:gaozifeng
 * @Date 2019/3/28 16:46
 **/
@Component
public class ConsumerRelateJTO extends BaseJson {


    /**
     * 返回实体信息
     *
     * @param table:
     * @return : com.fasterxml.jackson.databind.node.ObjectNode
     * @author : gaozifeng
     * @date : 2019/2/19 16:24
     */
    public static ObjectNode toJson(ConsumerRelateTO table) throws Throwable {
        ObjectNode root = MAPPER.createObjectNode();
        if (table != null) {
            root.putPOJO("consumerId", table.getConsumerId());
            root.putPOJO("phone", table.getPhone());
            toBaseJson(root, table);
        }
        return root;
    }

    public static ArrayNode toJson(List<ConsumerRelateTO> tables) throws Throwable {
        ArrayNode root = MAPPER.createArrayNode();

        if (!CommonUtil.isEmpty(tables))
            for (Iterator<ConsumerRelateTO> iterator = tables.iterator(); iterator.hasNext(); ) {
                root.add(toJson(iterator.next()));
            }

        return root;
    }
}
